﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CarLoanSystem.Entity;

namespace CarLoanSystem
{
    public partial class panelAppointments : UserControl
    {
        private static EmployeeItem empItem;
        public panelAppointments()
        {
            InitializeComponent();
            genGridview();
        }

        public void setEmployee(EmployeeItem item)
        {
            empItem = item;
        }

        private void genGridview()
        {
            // gen Grideview
            grvAppointMent.AutoGenerateColumns = false;

            //Set Columns Count
            grvAppointMent.ColumnCount = 6;

            //Add Columns
            grvAppointMent.Columns[0].Name = "LOAN_ID";
            grvAppointMent.Columns[0].HeaderText = "รหัสการขอกู้";
            grvAppointMent.Columns[0].DataPropertyName = "LOAN_ID";
            grvAppointMent.Columns[0].Width = 90;

            grvAppointMent.Columns[1].Name = "APPOINTMENTS_DATE";
            grvAppointMent.Columns[1].HeaderText = "วันที่นัดหมาย";
            grvAppointMent.Columns[1].DataPropertyName = "APPOINTMENTS_DATE";

            grvAppointMent.Columns[2].Name = "CUSTOMER_NAME";
            grvAppointMent.Columns[2].HeaderText = "ชื่อ";
            grvAppointMent.Columns[2].DataPropertyName = "CUSTOMER_NAME";

            grvAppointMent.Columns[3].Name = "CUSTOMER_LASTNAME";
            grvAppointMent.Columns[3].HeaderText = "นามสกุล";
            grvAppointMent.Columns[3].DataPropertyName = "CUSTOMER_LASTNAME";

            grvAppointMent.Columns[4].Name = "CUSTOMER_TEL";
            grvAppointMent.Columns[4].HeaderText = "เบอร์ติดต่อ";
            grvAppointMent.Columns[4].DataPropertyName = "CUSTOMER_TEL";

            grvAppointMent.Columns[5].Name = "APPOINTMENTS_TIME";
            grvAppointMent.Columns[5].HeaderText = "เวลา";
            grvAppointMent.Columns[5].DataPropertyName = "APPOINTMENTS_TIME";
            // end gen gridview
        }

        public void refreshGridview()
        {
            grvAppointMent.DataSource = LoadAppointment();
        }

        private DataTable LoadAppointment() 
        {
            DataTable dt = DAL.AppointmentsInfoDAL.LoadAppointmentALL(empItem.EMPLOYEE_ID, this.txtLoanId.Text, this.txtName.Text, this.txtLastName.Text);
            return dt;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            grvAppointMent.DataSource = LoadAppointment();
        }
    }
}
